package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * Description：
 * User：user
 * DATE:2021-10-29
 * Time:20:14
 */
public class DelOperation implements IOPeration {

    @Override
    public void work(BookList bookList){
        System.out.println("删除书籍");
        System.out.println("请输入图书的名字：");
        String name = scanner.nextLine();
        int size = bookList.getUsedSize();
        int index = 0;
        int i = 0;
        for (; i < size; i++) {
            Book bookCurrent = bookList.getBook(i);
            if(bookCurrent.getName().equals(name)){
                index = i;
                break;
            }
        }
        if(i == size){
            System.out.println("没有你要删除的书籍");
        }
        for (int j = index; j < size - 1; j++) {
                Book book = bookList.getBook(j + 1);
                bookList.setBooks(j,book);
        }
        bookList.setUsedSize(size - 1);
        System.out.println("删除成功了");
    }
}
